
var mainCustomerIds=sessionStorage.getItem("mainCustomerId")
var resetClassification3=0//三级重置操作
var operationclass=true//判断一级是查看还是操作true查看，flase操作
var notOperated=true//未操作
//var test=0  //点击加号即出现对应品牌
function selectBrand() {
    //test=1
    $("#selectInp").css({
        display:"block"
    });

    $("#aclick").css({
        display:"none"
    });
    $("#tuan").html("<li style='padding: initial;width: 130px;'>无数据</li> ");
    $("#tuan").show();

    $("#username").val("")

}
function brand_cancel() {
    $("#selectInp").css({
        display:"none"
    });
    $("#aclick").css({
        display:"inline"
    });

}


function myFunction(){
    //点击+号即出现品牌名
    $.ajax({
        url: root.goodsInter.goods_getListBrand,
        cache: false,  //禁用缓存
        type: "POST",
        data: {
            brandName:$("#username").val()
        },
        success: function (data) {
            var jsonObj =data.ListBrand;
            if(jsonObj==""){
                $("#tuan").html("<li style='padding: initial;width: 130px;'>无数据</li> ");
            }else {
                $("#tuan").show();
                var optionstring = "";
                for (var  i= 0; i < jsonObj.length; i++) {
                    optionstring += "<li style='padding: initial;width: 130px;' onclick='addCodeFun("+ jsonObj[i].brandId+ ",\""+jsonObj[i].brandName+ "\")'>"+jsonObj[i].brandName+ "</li>";
                }
                $("#tuan").html(optionstring);
            }
        }
    });
}
//品牌渲染用
var ListBrands=""
brandall()
function brandall() {
    $.ajax({
        url: root.goodsInter.goods_getListBrand,
        cache: false,  //禁用缓存
        type: "POST",
        async:false,//优先运行
        data: {
            brandName:""
        },
        success: function (data) {
            ListBrands=data.ListBrand
        }
    });
}
var brandName = "";
var brandId = "";
function addCodeFun(id,brand_name) {
    $("#tuan").hide();
    $("#username").val(brand_name)
    brandName = brand_name;
    brandId = id;
}
function upLoadFile() {
    $("#fileUp").trigger('click');
}
//删除
function removeModel(id) {
    $("#"+id).parent().remove();
}
function brand_sure() {
    /*sessionStorage.setItem("brand_name",brandName);
    sessionStorage.setItem("brand_id",brandId);*/
    console.log(brandId)
      if(brandId==""){
          layer.msg("请选择品牌", {icon: 5, time: 1000});
          return false;
      }
    $("#selectInp").css({
        display:"none"
    });
    $("#aclick").css({
        display:"inline"
    });
    $("#append").append("<div class=\"btn btn-secondary radius size-S ml-10\" name=\"brandMsg\">\n" +
        "<span >"+brandName+"</span>\n" +
        "<a id="+brandId+" onclick=\"removeModel(this.id)\" style='color: #ffffff'>×</a>\n" +
        "</div>");
    brandId = ""
    brandName=""
}

/*//渲染品牌名称
function addBrandName() {
    if(sessionStorage.getItem("brand_name")){
        $("#brandName").html(sessionStorage.getItem("brand_name"));
        $("#brandId").html(sessionStorage.getItem("brand_id"));
    }
}*/
/*-------------------------------------------------适用分类*/
//A计划
var map1={};
var map2={};
var map3=[];
var map4=[];
var firstLevel = [];
var secondLevel = [];
var thirdLevel = [];
var first = [];
var second = [];
var third = [];
var length2=0;
var thirdToFirst=[];
var selectall = 1;
var secondLevelall=[]//二级所有id
var classAall=[]//一级所有id
var four=[]


function makeMap(){
    firstLevel = [];
    for(key1 in map1){
        thirdToFirst=[];
        var lll=0;
        for(var i in map1[key1]){
            lll++
        }
        if(lll==0){
            firstLevel.push(key1);
        }
        for(key2 in map1[key1]){
            cateThird(key1,key2);
            cateSecond(key1,key2);
        }

    }
    console.log({"1":firstLevel, "2":secondLevel, "3":thirdLevel})
}
// 判断一级二级关系
function cateSecond(key1,key2){
    $.ajax({
        url: root.goodsInter.goods_subCategory,
        cache: false,  //禁用缓存
        type: "POST",
        dataType: 'json',
        async:false,
        data: {
            category_id: key1,
        },
        success: function (data) {
            var length=0;
            for(var i in map1[key1]){
                length++
            }
            if(length==data.data.length) {
                if(thirdToFirst.length==0&&$.inArray(key1,firstLevel)==-1){
                    firstLevel.push(key1);
                }
                else if(thirdToFirst.length!=0){
                    if($.inArray(key2,secondLevel)==-1){
                    }
                }
            }
            else if(length==0){
                firstLevel.push(key1);
            }
            else {
                if ($.inArray(key2, secondLevel) == -1) {
                    secondLevel.push(key2);
                }
            }
            //判断二级三级关系
            $.ajax({
                url: root.goodsInter.goods_subCategory,
                cache: false,  //禁用缓存
                type: "POST",
                dataType: 'json',
                async:false,
                // contentType: "application/json",
                data: {
                    category_id: key2,
                },
                success: function (data) {
                    if(data.data.length!=map1[key1][key2].length&&map1[key1][key2].length!=0)
                    {
                        secondLevel.remove(key2);
                    }
                },
                error: function () {

                }
            })
        },
        error: function () {

        }
    })
}


// 判断一级三级关系
function cateThird(key1,key2){
    $.ajax({
        url: root.goodsInter.goods_subCategory,
        cache: false,  //禁用缓存
        type: "POST",
        dataType: 'json',
        async:false,
        // contentType: "application/json",
        data: {
            category_id: key2,
        },
        success: function (data) {
            if(map1[key1][key2].length!=0&&map1[key1][key2].length!=data.data.length)
            {
                thirdToFirst=thirdToFirst.concat(map1[key1][key2]);
                for(var i=0;i<map1[key1][key2].length;i++){
                    if($.inArray(map1[key1][key2][i],thirdLevel==-1)){
                        thirdLevel.push(map1[key1][key2][i])
                    }
                }
            }
        },
        error: function () {

        }
    })
}

//数组删除某个元素
Array.prototype.indexOf = function(val) {
    for (var i = 0; i < this.length; i++) {
        if (this[i] == val) return i;
    }
    return -1;
};
Array.prototype.remove = function(val) {
    var index = this.indexOf(val);
    if (index > -1) {
        this.splice(index, 1);
    }
};
//字符串以什么结尾
String.prototype.endWith = function (endStr) {
    var d = this.length - endStr.length;
    return (d >= 0 && this.lastIndexOf(endStr) == d);
};

map_times={};
var firstlength=0;
var newArr=[]
goods_listCategory1(1);
function goods_listCategory1(classNum) {
    var user_data = {
        category_level: classNum
    }
    var succCallBack = function (data, status, response) {
        firstlength=data.data.length;
        if (data.data.length == 0) {
            $("#classSet1").append('<li class="clearfix pl-10 mb-5"  style="width: 95%" >无数据</li>');
        }
        else {

            for (var i = 0; i < data.data.length; i++) {
                classAall.push(data.data[i].category_id)
                map_times[data.data[i].category_id]=0;
                $("#classSet1").append('<li class="clearfix pl-10 mb-5"  style="width: 95%" ><div class="f-l pd-5">' +
                    '<input id="' + data.data[i].category_id + '" onclick="nextbox1(this,\''+data.data[i].category_code+'\',' +data.data[i].category_id + ')" name="classification01" type="checkbox" value="' + data.data[i].category_id + '" class="checkbox" />' +
                    '<label id="' + data.data[i].category_id + 'q" class="pl-10"  onclick="isFirstClick(2,' +data.data[i].category_id + ',this)">' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div>' +
                    '<div class="f-r"><a onclick="firstClassAdd(\'#firstClassInp2\',2,1,' + data.data[i].category_id + ',\'' + data.data[i].category_code + '\')" ></a>' +
                    '<a href="##" onclick="eidtInpShow(\'#firstClassInp1\',\'#addLabel1\',\'' + data.data[i].category_code + '\',\'.firstClassId1\',\'' + data.data[i].category_name + '\',' + data.data[i].category_id + ')" "></a>' +
                    '<a href="##" onclick="deleteGoodsClass(' + data.data[i].category_id + ')"></a></div></li>')
                newArr.push(data.data[i].category_id)
            }
        }
        pageShow()
    };
    return web.doAjax(root.goodsInter.goods_listCategory, 'post', user_data, succCallBack);
}

/* 一进来需要 请求回显接口 */
//不限
$("#box-1").attr("checked","checked");
var doc=0
var show=0
var arr=[];
var arri=[]
var arrii=[]
var fourdataArr=[]
var sedArr=[];
var thArr=[];
var fouridArr=[];

var sedCateIds=''
var sedelses=''
var thirIds=''
var oneIds=''
var datasnoe=""//记录一级id
var datassecond=""//记录二级id
var datatrue=true//一级操作
var datatrue2=true//二级操作
var datatrue3=true//三级操作
//渲染数据
function pageShow() {

    $.ajax({
        url: root.member.getProductPoolRule,
        // 告诉jQuery不要去处理发送的数据
        // 告诉jQuery不要去设置Content-Type请求头
        //contentType : false,
        cache: false,
        dataType: "json",
        type: "POST",
        data:{
            mainCustomerId:mainCustomerIds
        },
        success: function (data) {

            //回显
            if(data.data!=null && data.data!="") {
                datatrue=true
                datatrue2=true
                datatrue3=true
                //禁用按钮
                $("#disable").css({
                    display: "inline"
                });
                //品类
                if (data.data.categoryFilterType==10){
                    //适用
                    $("#radio-7").attr("checked","checked");
                }else if (data.data.categoryFilterType==20){
                    //排除
                    $("#radio-8").attr("checked","checked");
                }

                datasnoe=data.data.firstCategoryIds
                datassecond=data.data.secondCategoryIds
                show=1;
                //三级分类名称
                oneIds=data.data.firstCategoryIds
                sedelses=data.data.secondCategoryIds;
                sedCateIds=""
                thirIds=data.data.thirdCategoryIds
                /*一级品类id*/
                var firsts={}
                var firstsarr=[]
                var firstall=data.data.firstCategoryIds.split(",")
                for (var a=0;a<firstall.length;a++){
                    map1[Number(firstall[a])]={};
                    firsts={
                        "categoryId":Number(firstall[a])
                    }
                    firstsarr.push(firsts)
                }


                /*二级品类id*/
                var seconds={}
                var secondsarr=[]
                var secondall=data.data.secondCategoryIds.split(",")
                for (var b=0;b<secondall.length;b++){
                    map2[Number(secondall[b])]=[];
                    seconds={
                        "categoryId":Number(secondall[b])
                    }
                    secondsarr.push(seconds)
                }
                notOperated=true
                /*map1[3]=map2
                map2={}*/
                classas()
                /*三级品类id*/
                var thirdss={}
                var thirdarr=[]
                var thirdall=data.data.thirdCategoryIds.split(",")
                for (var c=0;c<thirdall.length;c++){
                    thirdss={
                        "categoryId":Number(thirdall[c])
                    }
                    thirdarr.push(thirdss)
                }
                /*四级品类id*/
                var fourss={}
                var fourarr=[]
                var fourall=""
                if(data.data.fourthCategoryIds!=null){
                    fourall=data.data.fourthCategoryIds.split(",")
                }else {
                    fourall=""
                }
                for (var d=0;d<fourall.length;d++){
                    fourss={
                        "categoryId":Number(fourall[d])
                    }
                    fourarr.push(fourss)
                }

                //排除分类名称(不选中的三级id)
                if(data.data.filterThirdCategoryIds!="" && data.data.filterThirdCategoryIds!=null){
                    var filterThirdCategoryIdsall=data.data.filterThirdCategoryIds.split(",")
                    for (var v=0;v<filterThirdCategoryIdsall.length;v++){
                        third.push(Number(filterThirdCategoryIdsall[v]))
                    }
                }
                //排除二级id
                classification02alls(2)
                second=secondLevelall
                if(data.data.secondCategoryIds!="" && data.data.secondCategoryIds!=null){
                    var secondCategoryIdsall=data.data.secondCategoryIds.split(",")
                    for (var m=0;m<secondLevelall.length;m++){
                        for (var u=0;u<secondCategoryIdsall.length;u++){
                            if(secondLevelall[m]!=secondCategoryIdsall[u]){
                                second.remove(secondCategoryIdsall[u])
                            }
                        }
                    }
                }
                //排除分类名称(不选中的四级id)
                if(data.data.filterFourthCategoryIds!="" && data.data.filterFourthCategoryIds!=null){
                    var filterFourthCategoryIdsall=data.data.filterFourthCategoryIds.split(",")
                    for (var n=0;n<filterFourthCategoryIdsall.length;n++){
                        four.push(filterFourthCategoryIdsall[n])
                    }
                }

                //一级品类id串
                arr = firstsarr

                sedArr = secondsarr

                thArr=thirdarr

                fouridArr=fourarr

                $.each(sedArr,function(i,newItem){
                    arri.push(newItem.categoryId)
                })
                /*所有的三级id*/
                $.each(thArr,function(i,newItem){
                    arrii.push(newItem.categoryId)
                })
                /*所有的四级id*/
                $.each(fouridArr,function(i,newItem){
                    fourdataArr.push(newItem.categoryId)
                })

                if (arr.length!=0){
                    doc=1
                }

                $.each(arr,function(i,newItem){
                    $.each(newArr,function(i,item){
                        if(newItem.categoryId==item){
                            $("#"+item).attr("checked","checked");
                        }
                    })
                })

                //品牌
                if (data.data.brandFilterType==20){
                    //适用
                    $("#box-2").attr("checked","checked");
                }else if (data.data.brandFilterType==30){
                    //排除
                    $("#box-3").attr("checked","checked");
                }else{
                    //不限
                    $("#box-1").attr("checked","checked");
                }

                //品牌
                if(data.data.brandIds!=""&& data.data.brandIds!=null) {
                    var  brandIdsall= data.data.brandIds.split(",")

                    for (var m = 0; m <ListBrands.length;m++){
                        for (var h = 0; h <brandIdsall.length;h++){
                            if(brandIdsall[h]==ListBrands[m].brandId){
                                $("#append").append("<div class=\"btn btn-secondary radius size-S ml-10\" name=\"brandMsg\">\n" +
                                    "<span >"+ListBrands[m].brandName+"</span>\n" +
                                    "<a id="+ListBrands[m].brandId+" onclick=\"removeModel(this.id)\" style='color: #ffffff'>×</a>\n" +
                                    "</div>");
                            }
                        }

                    }
                }

            }else {
                datatrue=false
                datatrue2=false
                datatrue3=false
                show=0;
                $("#disable").css({
                    display: "none"
                });

            }
            if (data.data) {
                if(data.data.showRestricted==0){
                    $("#showRestricted1").prop("checked",true)
                }else  if(data.data.showRestricted==1){
                    $("#showRestricted2").prop("checked",true)
                }
                if(data.data.showShieldProduct==0){
                    $("#showShieldProduct1").prop("checked",true)
                }else  if(data.data.showShieldProduct==1){
                    $("#showShieldProduct2").prop("checked",true)
                }
            }
        }
    });
}
//全部二级
var categoryid2=[]//全部二级
var classification02all=[]
function classification02alls(val) {
    categoryid2=[]
    var subCategorys=''
    if(val==1){
        subCategorys=classification02all
    }else {
        subCategorys= classAall
    }
    $.ajax({
        url: root.goodsInter.subCategorys,
        contentType: "application/json;charset=UTF-8",
        cache: false,  //禁用缓存
        type: "POST",
        dataType: 'json',
        async:false,//优先运行
        data: JSON.stringify(subCategorys),
        success: function (data) {
            if(val==1){
                //全选时方法
                //获取二级id作比较
                var secondCategoryIds = "";
                for(var i=0;i<data.data.length;i++){
                    categoryid2.push(data.data[i].category_id)
                    arri.push(data.data[i].category_id)
                    map2[Number(data.data[i].category_id)]=[];
                    secondCategoryIds += data.data[i].category_id+ ",";
                }
                //去掉最后一个逗号(如果不需要去掉，就不用写)
                if (secondCategoryIds.length > 0) {
                    secondCategoryIds = secondCategoryIds.substr(0, secondCategoryIds.length - 1);
                }
                datassecond=secondCategoryIds
                classas()
            }else {
                for(var i=0;i<data.data.length;i++){
                    secondLevelall.push(Number(data.data[i].category_id))
                }

            }


        }
    });
}
//全部三级
function classification03alls() {
    arrii=[]
    $.ajax({
        url: root.goodsInter.subCategorys,
        contentType: "application/json;charset=UTF-8",
        cache: false,  //禁用缓存
        type: "POST",
        dataType: 'json',
        data: JSON.stringify(categoryid2),
        success: function (data) {
            for(var i=0;i<data.data.length;i++){
                arrii.push(Number(data.data[i].category_id))
            }
        }
    });
}
//全选
$("#selectAll").click(function () {
    //一级
    $("input[name='classification01']").each(function(){
        $(this).prop("checked",true);
        classification02all.push(this.id)
        map1[this.id]={};

    });
    //获取一级id作比较
    var firstCategoryIds = "";
    for (var i = 0; i < classification02all.length; i++) {
        firstCategoryIds += classification02all[i]+ ",";
    }
    //去掉最后一个逗号(如果不需要去掉，就不用写)
    if (firstCategoryIds.length > 0) {
        firstCategoryIds = firstCategoryIds.substr(0, firstCategoryIds.length - 1);
    }
    datasnoe=firstCategoryIds
    //二级
    classification02alls(1)
    //三级
    third=[]
    //四级
    four=[]
    resetClassification3=0
    classification03alls()
    $("#classDiv2").css({
        display: "none"
    });
    $(".removeEl2").remove();
    $("#classDiv3").css({
        display: "none"
    });
    $("#classDiv4").css({
        display: "none"
    });
    selectall++;

})

//重置
function resetClassification(val){
    if(val==1){
        //一级
        $("input[name='classification01']").each(function(){
            $(this).prop("checked",false);

        });
        map1={};
        map2={};
        $("#classDiv2").css({
            display: "none"
        });
        $("#classDiv3").css({
            display: "none"
        });
        $("#classDiv4").css({
            display: "none"
        });
    } if(val==2){
        arri=[]
        //二级
        $("input[name='classification02']").each(function(){
            $(this).prop("checked",false);
            console.log(this.value)
            arri.remove(this.value)
            second.push(Number(this.value))
        });
        console.log(arri)
        var secondCategoryIds = "";
        for(var i=0;i<arri.length;i++){
            secondCategoryIds += arri[i]+ ",";
            map2[Number(arri[i])]=[];
        }
        //去掉最后一个逗号(如果不需要去掉，就不用写)
        if (secondCategoryIds.length > 0) {
            secondCategoryIds = secondCategoryIds.substr(0, secondCategoryIds.length - 1);
        }
        datassecond=secondCategoryIds
        classas()
        $("#classDiv3").css({
            display: "none"
        });
        $("#classDiv4").css({
            display: "none"
        });

    }else if(val==3){
        //三级
        resetClassification3=1
        $("input[name='classification03']").each(function(){
            $(this).prop("checked",false);
            third.push(Number(this.value))
            arrii.remove(Number(this.value))
        });

        $("#classDiv4").css({
            display: "none"
        });
    }

}

//判断是一级还是二级
function classas() {
    var user_data = {
        category_level: 2
    }
    var succCallBack = function (data, status, response) {
        //所有一级二级关系
        var cateObj = {};
        for (var h=0;h<data.data.length;h++) {
            var curPId =  data.data[h].parent_cate_id;
            var curSId = data.data[h].category_id
            if(cateObj.hasOwnProperty(curPId)){
                cateObj[curPId].push(curSId);
            }else{
                cateObj[curPId] = [];
                cateObj[curPId].push(curSId);
            }

        }
        //筛选选中的一级二级
        let map21 = {}
        for (f in cateObj) { // 遍历整理完成数据
            datasnoe.split(',').forEach(item2 => { // 遍历一级已选中数据
                if (item2 == f)  { // 已选中一级和所有一级做对比，同时存在，存储
                    map21[f] = {} // 创建一级key-value
                    cateObj[f].forEach(item => { // 一级下的所有二级数据
                        datassecond.split(',').forEach(item1 => { // 二级已选中数据
                            if (item1 == item) {
                                map21[f][item] = []
                            }
                        })
                    })
                }

            })
        }


    };
    return web.doAjax(root.goodsInter.goods_listCategory, 'post', user_data, succCallBack);
}

function nextbox1(that,valCode,parentId) {
    notOperated=false
    var Val = parseInt(that.value);
    if(that.checked){
        map1[Val]={};
        datatrue=false
    } else{
        datatrue=false
        $("#classDiv2").css({
            display: "none"
        });
        $("#classDiv3").css({
            display: "none"
        });
        $("#classDiv4").css({
            display: "none"
        });
        delete map1[Val];
    }
    map_times[parentId]=2;
    goods_listCategory2(2,Val,that.nextElementSibling)//渲染二级类
}

var oldparentId=0;
function goods_listCategory2(classNum, parentId, e) {
    operationclass=false
    if(e.previousElementSibling.checked){
        var checkbox = e.previousElementSibling;
        oldparentId=parentId;
        $(".removeEl2").remove();
        $("#classDiv2").css({
            display: "block"
        });
        $("#classDiv3").css({
            display: "none"
        });
        $("#classDiv4").css({
            display: "none"
        });
        var user_data = {
            category_id: parentId
        }
        var succCallBack = function (data, status, response) {
            if (data.data.length == 0) {
                $("#classSet2").append('<li class="removeEl2 clearfix pl-10 mb-5"  style="width: 95%" >无数据</li>');
            }
            else {
                //有数据
                for (var i = 0; i < data.data.length; i++) {
                    var categoryId = data.data[i].category_id;
                    if (show==1){
                        console.log("11111111111111111111111111")
                        if(checkbox.checked){
                            if(operationclass==true && parentId==datasnoe) {
                                if ($.inArray(categoryId, second) != -1) {
                                    $("#classSet2").append('<li class="removeEl2 clearfix pl-10 mb-5"  style="width: 95%" ><div class="f-l pd-5"><input onclick="nextbox2(this,' + data.data[i].category_code + ',' + parentId + ')"  name="classification02" type="checkbox" value="' + data.data[i].category_id + '"  class="" /><label class="pl-10 secondlevel" onclick="goods_listCategory3(3,' + data.data[i].category_id + ',' + parentId + ',this)">' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                                } else {
                                    $("#classSet2").append('<li class="removeEl2 clearfix pl-10 mb-5"  style="width: 95%" ><div class="f-l pd-5" ><input onclick="nextbox2(this,' + data.data[i].category_code + ',' + parentId + ')" name="classification02" type="checkbox" value="' + data.data[i].category_id + '" checked="checked" class="" /><label class="pl-10 secondlevel" onclick="goods_listCategory3(3,' + data.data[i].category_id + ',' + parentId + ',this)" >' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                                }
                            }else {
                                $("#classSet2").append('<li class="removeEl2 clearfix pl-10 mb-5"  style="width: 95%" ><div class="f-l pd-5" ><input onclick="nextbox2(this,' + data.data[i].category_code + ',' + parentId + ')" name="classification02" type="checkbox" value="' + data.data[i].category_id + '" checked="checked" class="" /><label class="pl-10 secondlevel" onclick="goods_listCategory3(3,' + data.data[i].category_id + ',' + parentId + ',this)" >' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                            }
                            $("input[name='classification02']").each(function(){
                                if(this.checked){
                                    map2[this.value]=[];
                                }
                            });
                            map1[parentId]=map2;
                            map2={};
                        } else{
                            $("#classSet2").append('<li class="removeEl2 clearfix pl-10 mb-5"  style="width: 95%" ><div class="f-l pd-5"><input onclick="nextbox2(this,\''+data.data[i].category_code+'\','+parentId+')"  name="classification02" type="checkbox" value="' + data.data[i].category_id + '"  class="" /><label class="pl-10 secondlevel" onclick="goods_listCategory3(3,' + data.data[i].category_id + ','+parentId+',this)">' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                        }
                    }else{
                        if(checkbox.checked){
                            if($.inArray(categoryId,second)!=-1){
                                $("#classSet2").append('<li class="removeEl2 clearfix pl-10 mb-5"  style="width: 95%" ><div class="f-l pd-5"><input onclick="nextbox2(this,\''+data.data[i].category_code+'\','+parentId+')"  name="classification02" type="checkbox" value="' + data.data[i].category_id + '"  class="" /><label class="pl-10 secondlevel" onclick="goods_listCategory3(3,' + data.data[i].category_id + ','+parentId+',this)">' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                            }
                            else {
                                $("#classSet2").append('<li class="removeEl2 clearfix pl-10 mb-5"  style="width: 95%" ><div class="f-l pd-5" ><input onclick="nextbox2(this,\''+data.data[i].category_code+'\','+parentId+')" name="classification02" type="checkbox" value="' + data.data[i].category_id + '" checked="checked" class="" /><label class="pl-10 secondlevel" onclick="goods_listCategory3(3,' + data.data[i].category_id + ','+parentId+',this)" >' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                            }
                            $("input[name='classification02']").each(function(){
                                if(this.checked){
                                    map2[this.value]=[];
                                }
                            });
                            map1[parentId]=map2;
                            map2={};
                        } else{
                            $("#classSet2").append('<li class="removeEl2 clearfix pl-10 mb-5"  style="width: 95%" ><div class="f-l pd-5"><input onclick="nextbox2(this,\''+data.data[i].category_code+'\','+parentId+')"  name="classification02" type="checkbox" value="' + data.data[i].category_id + '"  class="" /><label class="pl-10 secondlevel" onclick="goods_listCategory3(3,' + data.data[i].category_id + ','+parentId+',this)">' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                        }
                    }
                }
            }
        };
        return web.doAjax(root.goodsInter.goods_subCategory, 'post', user_data, succCallBack);
    }
}

function isFirstClick(classNum, parentId, e) {
    notOperated=false
    if (e.previousElementSibling.checked) {

        /* map_times[parentId]++;
         console.log(map_times[parentId])
         if (map_times[parentId]==1){
             goods_listCategory2(classNum, parentId, e)
             map_times[parentId]++
         }else {

         }*/
        goods_listCategory22(classNum, parentId, e)
    }
}

function goods_listCategory22(classNum, parentId, e) {
    console.log(parentId)
    console.log(datasnoe)
    operationclass=true
    if(e.previousElementSibling.checked){
        var checkbox = e.previousElementSibling;
        oldparentId=parentId;
        $(".removeEl2").remove();
        $("#classDiv2").css({
            display: "block"
        });
        $("#classDiv3").css({
            display: "none"
        });
        $("#classDiv4").css({
            display: "none"
        });
        var user_data = {
            category_id: parentId
        }
        var succCallBack = function (data, status, response) {
            if (data.data.length == 0) {
                $("#classSet2").append('<li class="removeEl2 clearfix pl-10 mb-5"  style="width: 95%" >无数据</li>');
            }
            else {
                //有数据

                var operations=2
                var firstall=datasnoe.split(",")
                for(var f=0;f<firstall.length;f++){
                    if(firstall[f]==parentId && datatrue==true){
                        operations=1
                    }
                }
                if (show==1){
                    console.log("2222222222222222222222222")
                    if (operations==1) {
                        //没有操作过
                        for (var i = 0; i < data.data.length; i++) {
                            var categoryId = data.data[i].category_id;
                            if ($.inArray(categoryId, arri)!=-1){
                                $("#classSet2").append('<li class="removeEl2 clearfix pl-10 mb-5"  style="width: 95%" ><div class="f-l pd-5" ><input onclick="nextbox2(this,\''+data.data[i].category_code+'\','+parentId+')" name="classification02" type="checkbox" value="' + data.data[i].category_id + '"  checked="checked" class="" /><label class="pl-10 secondlevel" onclick="goods_listCategory3(3,' + data.data[i].category_id + ','+parentId+',this)" >' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                                $("input[name='classification02']").each(function(){
                                    if(this.checked){
                                        map2[this.value]=[];
                                    }
                                });
                                map1[parentId]=map2;
                                map2={};
                            } else{
                                $("#classSet2").append('<li class="removeEl2 clearfix pl-10 mb-5"  style="width: 95%" ><div class="f-l pd-5" ><input onclick="nextbox2(this,\''+data.data[i].category_code+'\','+parentId+')" name="classification02" type="checkbox" value="' + data.data[i].category_id + '"  class="" /><label class="pl-10 secondlevel" onclick="goods_listCategory3(3,' + data.data[i].category_id + ','+parentId+',this)" >' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                            }}
                    }else {
                        //从新选中
                        for (var i = 0; i < data.data.length; i++) {
                            var categoryId = data.data[i].category_id;
                            if(checkbox.checked){
                                if(operationclass==true && parentId==datasnoe){
                                    if($.inArray(categoryId,second)!=-1){
                                        $("#classSet2").append('<li class="removeEl2 clearfix pl-10 mb-5"  style="width: 95%" ><div class="f-l pd-5"><input onclick="nextbox2(this,'+data.data[i].category_code+','+parentId+')"  name="classification02" type="checkbox" value="' + data.data[i].category_id + '"  class="" /><label class="pl-10 secondlevel" onclick="goods_listCategory3(3,' + data.data[i].category_id + ','+parentId+',this)">' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                                    } else {
                                        $("#classSet2").append('<li class="removeEl2 clearfix pl-10 mb-5"  style="width: 95%" ><div class="f-l pd-5" ><input onclick="nextbox2(this,'+data.data[i].category_code+','+parentId+')" name="classification02" type="checkbox" value="' + data.data[i].category_id + '" checked="checked" class="" /><label class="pl-10 secondlevel" onclick="goods_listCategory3(3,' + data.data[i].category_id + ','+parentId+',this)" >' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                                    }
                                }else {
                                    $("#classSet2").append('<li class="removeEl2 clearfix pl-10 mb-5"  style="width: 95%" ><div class="f-l pd-5" ><input onclick="nextbox2(this,\''+data.data[i].category_code+'\','+parentId+')" name="classification02" type="checkbox" value="' + data.data[i].category_id + '" checked="checked" class="" /><label class="pl-10 secondlevel" onclick="goods_listCategory3(3,' + data.data[i].category_id + ','+parentId+',this)" >' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                                }

                                $("input[name='classification02']").each(function(){
                                    if(this.checked){
                                        map2[this.value]=[];
                                    }
                                });
                            }
                            else{
                                $("#classSet2").append('<li class="removeEl2 clearfix pl-10 mb-5"  style="width: 95%" ><div class="f-l pd-5"><input onclick="nextbox2(this,\''+data.data[i].category_code+'\','+parentId+')"  name="classification02" type="checkbox" value="' + data.data[i].category_id + '"  class="" /><label class="pl-10 secondlevel" onclick="goods_listCategory3(3,' + data.data[i].category_id + ','+parentId+',this)">' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                            }
                        }
                    }

                }else{
                    for (var i = 0; i < data.data.length; i++) {
                        var categoryId = data.data[i].category_id;
                        if(checkbox.checked){
                            if($.inArray(categoryId,second)!=-1){
                                $("#classSet2").append('<li class="removeEl2 clearfix pl-10 mb-5"  style="width: 95%" ><div class="f-l pd-5"><input onclick="nextbox2(this,\''+data.data[i].category_code+'\','+parentId+')"  name="classification02" type="checkbox" value="' + data.data[i].category_id + '"  class="" /><label class="pl-10 secondlevel" onclick="goods_listCategory3(3,' + data.data[i].category_id + ','+parentId+',this)">' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                            }
                            else {
                                $("#classSet2").append('<li class="removeEl2 clearfix pl-10 mb-5"  style="width: 95%" ><div class="f-l pd-5" ><input onclick="nextbox2(this,\''+data.data[i].category_code+'\','+parentId+')" name="classification02" type="checkbox" value="' + data.data[i].category_id + '" checked="checked" class="" /><label class="pl-10 secondlevel" onclick="goods_listCategory3(3,' + data.data[i].category_id + ','+parentId+',this)" >' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                            }
                            $("input[name='classification02']").each(function(){
                                if(this.checked){
                                    map2[this.value]=[];
                                }
                            });
                        }
                        else{
                            $("#classSet2").append('<li class="removeEl2 clearfix pl-10 mb-5"  style="width: 95%" ><div class="f-l pd-5"><input onclick="nextbox2(this,\''+data.data[i].category_code+'\','+parentId+')"  name="classification02" type="checkbox" value="' + data.data[i].category_id + '"  class="" /><label class="pl-10 secondlevel" onclick="goods_listCategory3(3,' + data.data[i].category_id + ','+parentId+',this)">' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                        }
                    }}

            }
        };
        return web.doAjax(root.goodsInter.goods_subCategory, 'post', user_data, succCallBack);
    }
}



var oldparentIds = [];
function nextbox2(that,valCode,parentId) {
    var a=0;
    var b=[];
    var Val = parseInt(that.value)
    if(that.checked){
        datatrue2=false
        second.remove(Val)
        map2[Val]=[];
        map1[parentId]=map2;
        $("input[name='classification02']").each(function(){
            if(this.checked){
                a++
            }
        });
        var levelsecond = document.getElementsByName('classification02').length;
    }
    else{
        datatrue2=false
        second.push(Val)
        delete map1[parentId][Val];
        $("#classDiv3").css({
            display: "none"
        });
        $("#classDiv4").css({
            display: "none"
        });
        $("input[name='classification02']").each(function(){
            if(this.checked){
                b.push(parseInt(this.value));
            }
        });
        b=[];
    }
}
function goods_listCategory3(classNum, parentId, grandParentId, e) {
    var checkbox = e.previousElementSibling;
    if(checkbox.checked) {
        $("#classDiv3").css({
            display: "block"
        });
        $(".removeEl3").remove();
        var user_data = {
            category_id: parentId
        }
        var succCallBack = function (data, status, response) {
            if (data.data.length == 0) {
                $("#classSet3").append('<li class="removeEl3 clearfix pl-10 mb-5"  style="width: 95%" >无数据</li>');
            }
            else {
                for (var i = 0; i < data.data.length; i++) {
                    var categoryId = data.data[i].category_id
                    var newCategoryId = data.data[i].category_id
                    if (show==1){
                        var operations=2
                        console.log(datassecond)
                        var firstall=datassecond.split(",")
                        for(var f=0;f<firstall.length;f++){
                            if(firstall[f]==parentId && datatrue2==true){
                                operations=1
                            }
                        }
                    console.log(resetClassification3)
                    console.log(operations)
                        if (operations==1&& resetClassification3==1) {
                            console.log(arrii)
                            //没有操作过
                            if ($.inArray(newCategoryId,arrii)!=-1){
                                $("#classSet3").append('<li class="removeEl3 clearfix pl-10 mb-5"  style="width: 95%" ><div class="f-l pd-5" ><input onclick="nextbox3(this,\'' + data.data[i].category_code + '\',' + parentId + ',' + grandParentId + ')"  name="classification03" type="checkbox" value="' + data.data[i].category_id + '"  checked="checked"  class="checkbox" /><label class="pl-10" onclick="goods_listCategory4(4,' + data.data[i].category_id + ',' + parentId + ',this)">' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                            }
                            else{
                                $("#classSet3").append('<li class="removeEl3 clearfix pl-10 mb-5"  style="width: 95%" ><div class="f-l pd-5" ><input onclick="nextbox3(this,\'' + data.data[i].category_code + '\',' + parentId + ',' + grandParentId + ')"  name="classification03" type="checkbox" value="' + data.data[i].category_id + '"  class="checkbox" /><label class="pl-10" onclick="goods_listCategory4(4,' + data.data[i].category_id + ',' + parentId + ',this)">' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                            }
                        }else {
                            //操作过
                            console.log(third)
                            if (checkbox.checked) {
                                if ($.inArray(categoryId, third) != -1) {
                                    $("#classSet3").append('<li class="removeEl3 clearfix pl-10 mb-5"  style="width: 95%" ><div class="f-l pd-5" ><input onclick="nextbox3(this,\'' + data.data[i].category_code + '\',' + parentId + ',' + grandParentId + ')"  name="classification03" type="checkbox" value="' + data.data[i].category_id + '"  class="" /><label class="pl-10" onclick="goods_listCategory4(4,' + data.data[i].category_id + ',' + parentId + ',this)">' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                                }
                                else {
                                    $("#classSet3").append('<li class="removeEl3 clearfix pl-10 mb-5"  style="width: 95%" ><div class="f-l pd-5" ><input onclick="nextbox3(this,\'' + data.data[i].category_code + '\',' + parentId + ',' + grandParentId + ')"  name="classification03" type="checkbox" value="' + data.data[i].category_id + '" checked="checked" class="checkbox" /><label class="pl-10" onclick="goods_listCategory4(4,' + data.data[i].category_id + ',' + parentId + ',this)">' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                                }
                            }
                            else {
                                $("#classSet3").append('<li class="removeEl3 clearfix pl-10 mb-5"  style="width: 95%" ><div class="f-l pd-5" ><input onclick="nextbox3(this,\'' + data.data[i].category_code + '\',' + parentId + ',' + grandParentId + ')"  name="classification03" type="checkbox" value="' + data.data[i].category_id + '"  class="" /><label class="pl-10" onclick="goods_listCategory4(4,' + data.data[i].category_id + ',' + parentId + ',this)">' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                            }
                        }

                    }else{
                        if (checkbox.checked) {
                            if ($.inArray(categoryId, third) != -1) {
                                $("#classSet3").append('<li class="removeEl3 clearfix pl-10 mb-5"  style="width: 95%" ><div class="f-l pd-5" ><input onclick="nextbox3(this,\'' + data.data[i].category_code + '\',' + parentId + ',' + grandParentId + ')"  name="classification03" type="checkbox" value="' + data.data[i].category_id + '"  class="" /><label class="pl-10" onclick="goods_listCategory4(4,' + data.data[i].category_id + ',' + parentId + ',this)">' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                            }
                            else {
                                $("#classSet3").append('<li class="removeEl3 clearfix pl-10 mb-5"  style="width: 95%" ><div class="f-l pd-5" ><input onclick="nextbox3(this,\'' + data.data[i].category_code + '\',' + parentId + ',' + grandParentId + ')"  name="classification03" type="checkbox" value="' + data.data[i].category_id + '" checked="checked" class="checkbox" /><label class="pl-10" onclick="goods_listCategory4(4,' + data.data[i].category_id + ',' + parentId + ',this)">' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                            }
                        }
                        else {
                            $("#classSet3").append('<li class="removeEl3 clearfix pl-10 mb-5"  style="width: 95%" ><div class="f-l pd-5" ><input onclick="nextbox3(this,\'' + data.data[i].category_code + '\',' + parentId + ',' + grandParentId + ')"  name="classification03" type="checkbox" value="' + data.data[i].category_id + '"  class="" /><label class="pl-10" onclick="goods_listCategory4(4,' + data.data[i].category_id + ',' + parentId + ',this)">' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                        }
                    }
                }
                $("input[name='classification03']").each(function () {
                    if (this.checked) {
                        map3.push(this.value);
                    }
                });
                map1[grandParentId][parentId]= map3;
                map3 = [];
            }
        }
        return web.doAjax(root.goodsInter.goods_subCategory, 'post', user_data, succCallBack);
    }
}

function nextbox3(that,valCode, parentId, grandParentId) {
    var c=[]
    var thirds = 0;
    var seconds = 0;
    if(that.checked){
        datatrue3=false
        $("input[name='classification03']").each(function(){
            if(this.checked){
                map3.push(this.value);
                thirds++;
            }
        });
        $("input[name='classification02']").each(function(){
            if(this.checked){
                seconds++;
            }
        });
        var k=0;
        for(key in map1[grandParentId][parentId]){
            k++
        }
        map1[grandParentId][parentId]=map3;
        if(seconds==k){
            map1[grandParentId][parentId]=[];
        }
        map3=[];
        third.remove(that.value);
    }
    else{
        datatrue3=false
        third.push(that.value)
        $("input[name='classification03']").each(function(){
            if(this.checked){
                map3.push(this.value);
                c.push(parseInt(this.value))
            }
        });
        c=[];
        map1[grandParentId][parentId]=map3;
        map3=[];
    }
    console.log(map1)

}
function goods_listCategory4(classNum, parentId, grandParentId, e) {
    $("#classSet4").html("")
    var checkbox = e.previousElementSibling;
    if(checkbox.checked) {
        $("#classDiv4").css({
            display: "block"
        });
        $(".removeEl4").remove();
        var user_data = {
            category_id: parentId
        }
        var succCallBack = function (data, status, response) {
            if (data.data.length == 0) {
                $("#classSet4").append('<li class="removeEl3 clearfix pl-10 mb-5"  style="width: 95%" >无数据</li>');
            }
            else {
                for (var i = 0; i < data.data.length; i++) {
                    var categoryId = data.data[i].category_id.toString()
                    var newCategoryId = data.data[i].category_id
                    console.log( fourdataArr)
                    if (show==1){
                        var operations=2
                        var firstall=datassecond.split(",")
                        for(var f=0;f<firstall.length;f++){
                            if(firstall[f]==parentId && datatrue3==true){
                                operations=1
                            }
                        }
                        if (operations==1) {
                            //没有操作过
                            if ($.inArray(newCategoryId,fourdataArr)!=-1){
                                $("#classSet4").append('<li class="removeEl3 clearfix pl-10 mb-5"  style="width: 95%" ><div class="f-l pd-5" ><input onclick="nextbox4(this,\'' + data.data[i].category_code + '\',' + parentId + ',' + grandParentId + ')"  name="classification04" type="checkbox" value="' + data.data[i].category_id + '"  checked="checked"  class="checkbox" /><label class="pl-10" >' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                            }
                            else{
                                $("#classSet4").append('<li class="removeEl3 clearfix pl-10 mb-5"  style="width: 95%" ><div class="f-l pd-5" ><input onclick="nextbox4(this,\'' + data.data[i].category_code + '\',' + parentId + ',' + grandParentId + ')"  name="classification04" type="checkbox" value="' + data.data[i].category_id + '"  class="checkbox" /><label class="pl-10" >' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                            }
                        }else {
                            //操作过
                            if (checkbox.checked) {
                                if ($.inArray(categoryId, four) != -1) {
                                    $("#classSet4").append('<li class="removeEl3 clearfix pl-10 mb-5"  style="width: 95%" ><div class="f-l pd-5" ><input onclick="nextbox4(this,\'' + data.data[i].category_code + '\',' + parentId + ',' + grandParentId + ')"  name="classification04" type="checkbox" value="' + data.data[i].category_id + '"  class="" /><label class="pl-10" >' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                                }
                                else {
                                    $("#classSet4").append('<li class="removeEl3 clearfix pl-10 mb-5"  style="width: 95%" ><div class="f-l pd-5" ><input onclick="nextbox4(this,\'' + data.data[i].category_code + '\',' + parentId + ',' + grandParentId + ')"  name="classification04" type="checkbox" value="' + data.data[i].category_id + '" checked="checked" class="checkbox" /><label class="pl-10" >' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                                }
                            }
                            else {
                                $("#classSet4").append('<li class="removeEl3 clearfix pl-10 mb-5"  style="width: 95%" ><div class="f-l pd-5" ><input onclick="nextbox4(this,\'' + data.data[i].category_code + '\',' + parentId + ',' + grandParentId + ')"  name="classification04" type="checkbox" value="' + data.data[i].category_id + '"  class="" /><label class="pl-10" >' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                            }
                        }

                    }else{
                        if (checkbox.checked) {
                            if ($.inArray(categoryId, four) != -1) {
                                $("#classSet4").append('<li class="removeEl3 clearfix pl-10 mb-5"  style="width: 95%" ><div class="f-l pd-5" ><input onclick="nextbox4(this,\'' + data.data[i].category_code + '\',' + parentId + ',' + grandParentId + ')"  name="classification04" type="checkbox" value="' + data.data[i].category_id + '"  class="" /><label class="pl-10">' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                            }
                            else {
                                $("#classSet4").append('<li class="removeEl3 clearfix pl-10 mb-5"  style="width: 95%" ><div class="f-l pd-5" ><input onclick="nextbox4(this,\'' + data.data[i].category_code + '\',' + parentId + ',' + grandParentId + ')"  name="classification04" type="checkbox" value="' + data.data[i].category_id + '" checked="checked" class="checkbox" /><label class="pl-10">' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                            }
                        }
                        else {
                            $("#classSet4").append('<li class="removeEl3 clearfix pl-10 mb-5"  style="width: 95%" ><div class="f-l pd-5" ><input onclick="nextbox4(this,\'' + data.data[i].category_code + '\',' + parentId + ',' + grandParentId + ')"  name="classification04" type="checkbox" value="' + data.data[i].category_id + '"  class="" /><label class="pl-10" ">' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                        }
                    }
                }
                $("input[name='classification04']").each(function () {
                    if (this.checked) {
                        map4.push(this.value);
                    }
                });
                console.log(grandParentId)
                console.log(parentId)
                map1[grandParentId][parentId]= map4;

                map4 = [];
            }
        }
        return web.doAjax(root.goodsInter.goods_subCategory, 'post', user_data, succCallBack);
    }
}

function nextbox4(that,valCode, parentId, grandParentId) {
    var c=[]
    var fours = 0;
    var seconds = 0;
    if(that.checked){
        $("input[name='classification04']").each(function(){
            if(this.checked){
                map4.push(this.value);
                fours++;
            }
        });
        $("input[name='classification02']").each(function(){
            if(this.checked){
                seconds++;
            }
        });
        four.remove(that.value);
        var k=0;
        for(key in map1[grandParentId][parentId]){
            k++
        }
        map1[grandParentId][parentId]=map4;
        if(seconds==k){
            map1[grandParentId][parentId]=[];
        }
        map4=[];
        console.log(that.value)

    }
    else{
        four.push(that.value)
        $("input[name='classification04']").each(function(){
            if(this.checked){
                map4.push(this.value);
                c.push(parseInt(this.value))
            }
        });
        c=[];
        map1[grandParentId][parentId]=map4;
        map4=[];
    }

}



//保存
var isIng = false;
function preservationLists() {
    console.log(notOperated)


    if(isIng){
        layer.msg('请求已提交，请勿重复点击！');
        return false;
    }
    isIng = true;

    if ($("input[name=applCate]:checked").val() == undefined) {
        layer.msg("规则不能为空", {icon: 5, time: 1000});
        isIng = false;
        return;
    }
    makeMap();
    var sedCateId = [];
    var sedelse = [];
    var thirId = [];
    var oneId = [];

    for (i in map1) {
        oneId.push(i);
        for (s in map1[i]) {
            if (map1[i][s].length == 0) {
                sedCateId.push(s);
            } else {
                sedelse.push(s);
                $.each(map1[i][s], function (i, item) {
                    thirId.push(item);
                })
            }
        }
    }
    if(notOperated==true){
        sedelse=[]
        for (m in map2) {
            sedelse.push(m);
        }
    }else {
        sedelse=sedelse
    }
    //选中的二级
    var secondCategoryIdsall=""
    if(sedelse!=""){
        for (var f=0;f<sedelse.length;f++) {
            secondCategoryIdsall+=sedelse[f]+','
        }
    }
    for (var d=0;d<sedCateId.length;d++) {
        secondCategoryIdsall+=sedCateId[d]+','

    }
    //去掉最后一个逗号(如果不需要去掉，就不用写)
    if (secondCategoryIdsall.length > 0) {
        secondCategoryIdsall = secondCategoryIdsall.substr(0, secondCategoryIdsall.length - 1);
    }

    thirIds = thirId.join(',')
    oneIds = oneId.join(',')

    //三级不勾选的数据
    var filterThirdCategoryIdsall=""
    for (var e=0;e<third.length;e++) {
        filterThirdCategoryIdsall+=third[e]+','
    }
    //去掉最后一个逗号(如果不需要去掉，就不用写)
    if (filterThirdCategoryIdsall.length > 0) {
        filterThirdCategoryIdsall = filterThirdCategoryIdsall.substr(0, filterThirdCategoryIdsall.length - 1);
    }
    //四级不勾选的数据
    var filterFourthCategoryIds=""
    for (var f=0;f<four.length;f++) {
        filterFourthCategoryIds+=four[f]+','
    }
    //去掉最后一个逗号(如果不需要去掉，就不用写)
    if (filterFourthCategoryIds.length > 0) {
        filterFourthCategoryIds = filterFourthCategoryIds.substr(0, filterFourthCategoryIds.length - 1);
    }


    if (oneIds.length == 0 && doc == 0) {
        layer.msg("规则不能为空", {icon: 5, time: 1000});
        isIng = false;
        return;
    }
    var brandIds = []

    $("#append a[id]").each(function () {
        brandIds.push($(this).attr("id"))
    })
    if ($("input[name=brand]:checked").val() != 10
        && brandIds.length == 0) {
        layer.msg("规则不能为空", {icon: 5, time: 1000});
        isIng = false;
        return;
    }
    var noSend = 0
    $.each(brandIds, function (i, first) {
        $.each(brandIds, function (s, sed) {
            if (i == s) {
                return true;
            }
            if (first == sed) {
                layer.msg("品牌相同,请重试", {icon: 5, time: 1000});
                isIng = false;
                noSend = 1;
            }
        })
    })
    console.log($("input[name=showRestricted]:checked").val())
    if ($("input[name=showRestricted]:checked").val() == undefined) {
        layer.msg("规则不能为空", {icon: 5, time: 1000});
        isIng = false;
        return;
    }

    if ($("input[name=showShieldProduct]:checked").val() == undefined) {
        layer.msg("是否展示屏蔽商品-规则不能为空", {icon: 5, time: 1000});
        isIng = false;
        return;
    }

    //保存提示
    if (noSend == 1) {
        return;
    }
    var brandIdsall=""
    if($("input[name=brand]:checked").val()==10){
        brandIdsall=""
    }else {
        brandIdsall=brandIds.join(',')
    }
    /*console.log("一级"+oneIds)
    console.log("二级"+secondCategoryIdsall)
    console.log("三级"+filterThirdCategoryIdsall)
    console.log("四级"+filterFourthCategoryIds)
    return false;*/

    if(oneIds=="" || secondCategoryIdsall==""){
        layer.msg("规则不能为空", {icon: 5, time: 1000});
        isIng = false;
        return;
    }

    $.ajax({
        contentType: 'application/json',
        url: root.member.saveProductPoolRule,
        cache: false,  //禁用缓存
        type: "POST",
        data: JSON.stringify({
            "mainCustomerId": mainCustomerIds,
            "operateUserId": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.user_ID,
            "operateUserName": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.name,
            "categoryFilterType": $("input[name=applCate]:checked").val(),
            "firstCategoryIds": oneIds,
            "secondCategoryIds": secondCategoryIdsall,
            "filterThirdCategoryIds": filterThirdCategoryIdsall,
            "brandIds": brandIdsall,
            "brandFilterType": $("input[name=brand]:checked").val(),
            "showRestricted":$("input[name=showRestricted]:checked").val(),
            "filterFourthCategoryIds":filterFourthCategoryIds,
            "showShieldProduct":$("input[name=showShieldProduct]:checked").val()

        }),

        success: function (data) {
            if (data.errorCode == 0) {
                $.Huimodalalert('规则设置成功', 3000);
                setTimeout(function () {
                    location.replace(location.href)
                    isIng = false;
                }, 700);

            } else {
                layer.msg(data.msg, {icon: 5, time: 1000});
                isIng = false;
            }

        },
        error: function () {
            layer.msg("保存失败,请重新提交！", {icon: 5, time: 1000});
            isIng = false;
        }
    });
}
//禁用
var isIng2 = false;
function disable() {
    if(isIng2){
        layer.msg('请求已提交，请勿重复点击！');
        return false;
    }
    isIng2 = true;
    var cu = layer.confirm('<span>您即将禁用该客户组的定制商品池规则，请确认</span>', {title:'提示',btn: ['确认', '取消']}, function(index){
        $.ajax({
            url: root.member.cancelProductPoolRule,
            cache: false,
            dataType: "json",
            type: "POST",
            data:{
                mainCustomerId:mainCustomerIds
            },
            success: function (data) {
                if (data.errorCode == 0) {
                    layer.msg("规则禁用成功！", {icon: 6, time: 1000});
                    setTimeout(function () {
                        location.replace(location.href)
                        isIng2 = true;
                    }, 700);

                } else {
                    $.Huimodalalert(data.msg, 3000);
                    isIng2 = false;
                }
            }
        })
        layer.close(cu);
    },function(){
        layer.close(cu);
        isIng2 = false;

    });

}